<%--
  @author rominamilea@gmail.com
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<form:form id="q_content" commandName="questionnaire">
    <c:choose>
        <c:when test="${not empty questionsList}">
            <c:set var="questionsList" value="${questionsList}">
            </c:set>
            <c:set var="i" value="0"/>
            <ol>
                <c:forEach items="${questionsList}" var="question">
                    <li>
                            ${question.text}
                        <div id="radioGroup">
                            <ol class="no_style">
                                <c:forEach items="${question.responses}" var="response" varStatus="loop">
                                    <c:choose>
                                        <c:when test="${question.responseType == 'SINGLE'}">
                                            <form:radiobutton path="questions[${i}].responses[0].id"
                                                              label="${response.text}"
                                                              value="${response.id}"/>
                                            <br/>
                                        </c:when>
                                        <c:otherwise>
                                            <form:checkbox path="questions[${i}].responses[${loop.count-1}].id"
                                                           label="${response.text}"
                                                           value="${response.id}"/>
                                            <br/>
                                        </c:otherwise>
                                    </c:choose>
                                </c:forEach>
                            </ol>
                        </div>
                    </li>
                    <c:set var="i" value="${i + 1}"/>
                </c:forEach>
            </ol>
            <%--<input type="submit" class="no_border" onclick=""/>--%>
            <div id="submitQ">
                <a class="underline_" href="#" onclick="submitQuestionnaire()">Submit questionnaire</a>
            </div>
            <div id="successSubmit">
                <a class="underline_" href="#" onclick="showStatistics('${id}');">View the statistics for
                    this questionnaire</a>
                <h4>Thanks for taking your time to fill in this questionnaire.</h4>
            </div>
            <br/>
            <br/>

        </c:when>
        <c:otherwise>
            <h4>We are sorry, but there is no questions for your selection.</h4>
        </c:otherwise>
    </c:choose>
</form:form>